#ifndef _DATAHANDLE_H_
#define _DATAHANDLE_H_
#include "type.h"
#include "cli_main.h"
bool initsqlite(); 
void getRecordMaxIdAndMinId(I32* maxId, I32* minId, I32 type);
bool savePhoneInfo(I32 id, U32 uptime, I8 *imsi, I8 *imei, I32 slotId);
void getDbRecord(bool oldData, RECORDINFO *recordInfo, I32 *startIndex, I32 *endIndex, bool intervalUse);
void getUploadFailedRecord(RECORDINFO *recordInfo, I32 startIndex, I32 endIndex);

bool saveMacInfo(I32 id, U32 uptime, I8 *mac);
void getDbMacRecord(bool oldData, MACRECORDINFO *recordInfo, I32 *startIndex, I32 *endIndex, bool intervalUse);
void getUploadMacFailedRecord(MACRECORDINFO *recordInfo, I32 startIndex, I32 endIndex);

void delDbRecord(I32 startIndex, I32 endIndex, I32 type);
void sqliteStartTransaction();
bool sqliteCommitTransaction();
bool rmDbAndinitSqlite();
bool saveMacToFtpFileOrSendByUdp(const char *filename, I32 *rows, I32 *minId, I32 *maxId);
void sendImsiByUdp(I32 *minId, I32 *maxId);

#define MAX_USER_RECORD 10
typedef struct
{
    U8 num;
    U32 userTm[MAX_USER_RECORD] ;
    char targetImsi[MAX_USER_RECORD][512];
    char userName[MAX_USER_RECORD][24];
    char userId[MAX_USER_RECORD][24];
    char catchImsi[MAX_USER_RECORD][128];
} USERRECORD;


void saveUserRecord(char *imsiList, char* userName, char *userId);
void updateRecord(char *imsi);
void packrecordInStruct(U32 *currentTm, U32 *startTm, U32 endTm, USERRECORD *user);
#endif
